package com.csx.base.design.behavior.chainOfResponsibility.example.exampleA;

import com.csx.base.design.behavior.chainOfResponsibility.example.exampleA.handler.AbstractCheckHandler;
import com.csx.base.design.behavior.chainOfResponsibility.example.exampleA.model.vo.ProductVO;
import com.csx.base.design.behavior.chainOfResponsibility.example.exampleA.model.vo.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 负责发起整个处理器链路的执行，通过executeChain()， 如果处理器链路返回错误信息，则校验未通过，整个链路被截断
 * @author cuisongxu
 * @date 2022/12/28 22:54
 */
public class HandlerClient {

    private static final Logger logger = LoggerFactory.getLogger(HandlerClient.class);

    public static Result executeChain(AbstractCheckHandler handler, ProductVO param) {

        // 执行处理器
        Result handleResult = handler.handle(param);
        if(!handleResult.isSuccess()) {
            logger.warn("handlerClient 执行失败返回，失败原因: " + handleResult.getMessage());
            return handleResult;
        }
        return Result.success();
    }
}
